<style type="text/css">
    #txtAddress1.form-control:focus,
    #txtAddress2.form-control:focus {
        z-index: 2;
    }
    
    #txtAddress1,
    #txtAddress2 {
        position: relative;
    }
    
    #txtAddress1 {
        border-bottom-left-radius: 0px; 
        border-bottom-right-radius: 0px; 
        margin-bottom:-1px;
    }
    
    #txtAddress2 {
        border-top-left-radius: 0px; 
        border-top-right-radius: 0px;
    }
</style>

<h4>Providers</h4>
<div id="alertContainer"></div>

<div class="btn-group" role="group" aria-label="Provider Controls">
    <button type="button" id="btnSelectAll" class="btn btn-default" data-toggle="button" aria-pressed="false" autocomplete="off">
        <span ng-class="{'glyphicon glyphicon-check': selectAll.selected, 'glyphicon glyphicon-unchecked': !selectAll.selected}"></span>
    </button>
    <button type="button" class="btn btn-default" ng-click="createProvider()" data-toggle="modal" data-target="#dlgEditProvider">
        <span class="glyphicon glyphicon-plus"></span>
    </button>
    <button type="button" class="btn btn-default" data-toggle="modal" data-target="#dlgDeleteProviders">
        <span class="glyphicon glyphicon-trash"></span>
    </button>
</div>

<table class="table table-striped table-hover" ng-table="tableParameters">
    <tbody>
        <tr ng-repeat="provider in $data">
            <td>
                <div class="checkbox">
                    <input type="checkbox" ng-model="provider.selected" ng-change="updateSelectAll()" style="margin: 0px !important; display: inline-block;" />
                </div>
            </td>
            <td>
                <button class="btn btn-default" ng-click="editProvider(provider.id)" data-toggle="modal" data-target="#dlgEditProvider" style="margin-right: 10px;">
                    <span class="glyphicon glyphicon-pencil"></span> Edit
                </button>
                <button class="btn btn-danger" ng-click="setProvider(provider)" data-toggle="modal" data-target="#dlgDeleteProvider">
                    <span class="glyphicon glyphicon-trash"></span> Delete
                </button>
            </td>
            <td data-title="'First Name'" style="text-align: left;" sortable="'fName'">{{ provider.fName }}</td>
            <td data-title="'Middle Initial'" style="text-align: center;" sortable="'middleInitial'">{{ provider.middleInitial }}</td>
            <td data-title="'Last Name'" style="text-align: left;" sortable="'lName'">{{ provider.lName }}</td>
            <td data-title="'Phone #'" style="text-align: left;" sortable="'phone'">{{ provider.phone }}</td>
            <td data-title="'City'" style="text-align: left;" sortable="'city'">{{ provider.city }}</td>
            <td data-title="'State'" style="text-align: center;" sortable="'state'">{{ provider.state }}</td>
            <td data-title="'Gender'" style="text-align: center;" sortable="'gender'">{{ provider.gender == 'M' ? 'Male' : 'Female' }}</td>
        </tr>
    </tbody>
</table>

<div class="modal fade" id="dlgDeleteProvider" tabindex="-1" role="dialog" aria-labelledby="dlgDeleteProviderTitle" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form id="deleteProviderForm">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    
                    <h4 class="modal-title" id="dlgDeleteProviderTitle">Delete Provider</h4>
                </div>
                
                <div class="modal-body">
                    <strong>Confirm!</strong> Are you sure you wish to delete this provider?
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" ng-model="button">Cancel</button>
                    <button type="button" class="btn btn-danger" aria-label="Delete" ng-click="deleteProvider()" data-dismiss="modal">
                        <span class="glyphicon glyphicon-trash"></span>
                        Delete
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="dlgDeleteProviders" tabindex="-1" role="dialog" aria-labelledby="dlgDeleteProvidersTitle" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form id="deleteProvidersForm">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    
                    <h4 class="modal-title" id="dlgDeletePatientsTitle">Delete Provider(s)</h4>
                </div>
                
                <div class="modal-body">
                    <strong>Confirm!</strong> Are you sure you wish to delete the following provider(s)?
                    <table class="table">
                        <thead>
                            <th>First Name</th>
                            <th>Middle Initial</th>
                            <th>Last Name</th>
                        </thead>
                        <tbody>
                            <tr ng-repeat="provider in selectedProviders()">
                                <td>{{ provider.fName }}</td>
                                <td>{{ provider.middleInitial }}</td>
                                <td>{{ provider.lName }}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" ng-model="button">Cancel</button>
                    <button type="button" class="btn btn-danger" aria-label="Delete" ng-click="deleteProviders()" data-dismiss="modal">
                        <span class="glyphicon glyphicon-trash"></span>
                        Delete
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="dlgEditProvider" tabindex="-1" role="dialog" aria-labelledby="dlgEditProviderModalTitle" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form name="editProviderForm" id="editProviderForm">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    
                    <h4 class="modal-title" id="dlgEditProviderModalTitle">{{ mode }} Provider</h4>
                </div>
                
                <div class="modal-body">
					<div class="alert alert-danger" role="alert" ng-show="errorMessages.length > 0">
					    <ul>
					        <li ng-repeat="error in errorMessages"><strong>{{ error.label }}</strong> {{ error.message }}</li>
					    </ul>
					</div>
					<div class="form-group">
					    <label for="txtFirstName" class="control-label">First Name</label>
					    <input type="text" id="txtFirstName" name="txtFirstName" class="form-control" ng-model="editingProvider.fName" maxlength="40" required />
					</div>
					<div class="form-group">
					    <label for="txtMiddleInitial" class="control-label">Middle Initial</label>
					    <input type="text" id="txtMiddleInitial" name="txtMiddleInitial" class="form-control" ng-model="editingProvider.middleInitial" maxlength="1" />
					</div>
					<div class="form-group">
					    <label for="txtLastName" class="control-label">Last Name</label>
					    <input type="text" id="txtLastName" name="txtLastName" class="form-control" ng-model="editingProvider.lName" maxlength="40" required />
					</div>
					<div class="form-group">
					    <label for="txtPhone" class="control-label">Phone #</label>
					    <input type="text" id="txtPhone" name="txtPhone" class="form-control" ng-model="editingProvider.phone" maxlength="20" ui-mask="(999) 999-9999" />
					</div>
					<div class="form-group">
                           <label class="control-label">Address</label>
                           <label class="sr-only" for="txtAddress1">Address 1</label>
                           <input type="text" id="txtAddress1" name="txtAddress1" class="form-control" aria-label="Address 1" placeholder="Address 1" ng-model="editingProvider.address1" maxlength="40" />
                           <label class="sr-only" for="txtAddress2">Address 2</label>
                           <input type="text" id="txtAddress2" name="txtAddress2" class="form-control" aria-label="Address 2" placeholder="Address 2" ng-model="editingProvider.address2" maxlength="40" />
                       </div>
					<div class="form-group">
                           <label for="txtCity" class="control-label">City</label>
                           <input type="text" id="txtCity" name="txtCity" class="form-control" ng-model="editingProvider.city" maxlength="40" />
                       </div>
                       <div class="form-group">
                           <label for="txtState" class="control-label">State</label>
                           <input type="text" id="txtState" name="txtState" class="form-control" ng-model="editingProvider.state" ng-maxlength="2" />
                       </div>
                       <div class="form-group">
                           <label for="ddlGender" class="control-label">Gender</label>
                           <select id="ddlGender" name="ddlGender" class="form-control" ng-model="editingProvider.gender" ng-options="genderOption.value as genderOption.label for genderOption in genderOptions"></select>
                       </div>
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" ng-model="button">Close</button>
                    <button type="button" class="btn btn-success" aria-label="Save" ng-click="saveProvider()">
                        <span class="glyphicon glyphicon-save"></span>
                        Save
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>